/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare.VehicleInfoPanel');
(function () {
	
	/**
	 * Panel to display a selected vehicle's information (model year, make, model, trim, msrp, image, etc)
	 * @class VehicleInfoPanel
	 * @extends Ext.Component
	 * @namespace net.autodata.compare
	 */
	var Panel = Ext.extend(Ext.Component, {
		autoEl: {
			tag: 'div',
			cls: 'vehicleInfo-panel'
		},
		
		/**
		 * @property view
		 * @type Object
		 */
		view: undefined,
		
		viewCfg: undefined,
		
		/**
		 * @property data
		 * @type Object
		 */
		data: undefined,
		
		constructor: function (cfg)
		{
			cfg = cfg || {};
			
			//Apply the cfg params to the object
			Ext.apply(this, cfg);
			this.initialCfg = cfg;
			
			Panel.superclass.constructor.call(this, cfg);
		},
		
		initComponent: function ()
		{
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();
			view.init(this);
		},
		
		/**
		 * @method getView
		 * @returns Object
		 */
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.VehicleInfoView(this.viewCfg);
			}
			return this.view;
		},
		
		/**
		 * @method setData
		 * @param {Object} newData
		 */
		setData: function (newData)
		{
			this.data = newData;
			if (this.el) {
				this.getView().render();
			}
		},
		
		/**
		 * @method getData
		 * @returns Object
		 */
		getData: function ()
		{
			return this.data;
		},
		
		/**
		 * @method onRender
		 * @private
		 */
		onRender: function ()
		{
			Panel.superclass.onRender.apply(this, arguments);
			var view = this.getView();
			view.render();
		},
		
		/**
		 * @method onDestroy
		 * @private
		 */
		onDestroy: function ()
		{
			Panel.superclass.onDestroy.apply(this, arguments);
			
		}		
	});	
	
	net.autodata.compare.VehicleInfoPanel = Panel;
})();